package com.mgvlife.ddlw.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.mgvlife.ddlw.formbean.CourseForm;
import com.mgvlife.ddlw.service.CourseService;
import com.mgvlife.ddlw.vo.Result;
import com.mgvlife.ddlw.vo.VoCourse;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xinhuo.util.JsonUtil;
import com.xinhuo.vo.JsonEasyUI;

@Controller("courseAction")
@Scope("prototype")
public class CourseAction extends ActionSupport implements
		ModelDriven<CourseForm> {

	private static final long serialVersionUID = 7862406371446431713L;
	private CourseForm dataForm = new CourseForm();
	@Resource
	private CourseService courseService = null;

	public void add() {
		Result result = null;
		try {
			result = courseService.courseAdd(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void update() {
		Result result = null;
		try {
			result = courseService.courseUpdate(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void list() {
		JsonEasyUI<VoCourse> result = null;
		try {
			result = courseService.getData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}
	
	public void listAll() {
		JsonEasyUI<VoCourse> result = null;
		try {
			result = courseService.getAllData();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void delete() {
		Result result = null;
		try {
			result = courseService.courseDelete(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	@Override
	public CourseForm getModel() {
		return dataForm;
	}

}
